<%@page import="java.io.Reader"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
	body {
	font-family: '나눔고딕';
	font-size: 14px;
	font-weight: bold;
	color: red;
	margin-top: 100px;
	background-image: url('../images/main.jpg');
	background-size: 55% 57%;
	}
	.bw_btn{
		background-color: black;
		color: red;
		font-weight: bold;
		font-size: 15px;
	}
	.b_tb{
		background-color: black;
	}
	.bw_td{
		color: red;
		font-weight: bold;
		font-size: 20px;
	}
</style>
<script src="<%=request.getContextPath()%>/se2/js/HuskyEZCreator.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=request.getContextPath()%>/se2/photo_uploader/plugin/hp_SE2M_AttachQuickPhoto.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/se2/js/HuskyEZCreator.js" charset="utf-8"></script>
<script type="text/javascript">
	function fnEdit(frm) {
		var sHTML = oEditors.getById["textAreaContent"].getIR();
		frm.content.value=sHTML;
		frm.submit();
	}
</script>
</head>
<body>
	<%
		String driver = "oracle.jdbc.driver.OracleDriver";
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
		String db_user = "semi";
		String db_pwd = "semi";
		Connection con; 
		PreparedStatement psmt;
		ResultSet rs;
		StringBuilder sb = null;
		int cnt1=0;
		try {
			con = DriverManager.getConnection(url, db_user, db_pwd);
			System.out.println("DB접속 성공");
			
			String sql3 ="select content from test where no=2";
			psmt = con.prepareStatement(sql3);
			rs = psmt.executeQuery();
			if(rs.next()){
				Reader rd  = rs.getCharacterStream("content");
				sb = new StringBuilder();
				char[] buff = new char[1024];
				int read=0;
				while((read = rd.read(buff,0,1024))!=-1){
					sb.append(buff,0,read);
				}
			}
			rs.close();
			psmt.close();
			con.close();
			System.out.println("죄회끝");	
		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
	<%-- <form action="${pageContext.request.contextPath }/homepage/bbs/BEResult.jsp" method="post" onsubmit="fnEdit(this)"> --%>
	<form action="${pageContext.request.contextPath }/homepage/bbs/BERMB.jsp" method="post" onsubmit="fnEdit(this)">
		<div align="center" id="bw_div">
			<h1>글 수정</h1>
			<table class="b_tb" width="75%">
				<tr>
					<td class="bw_td">글 유형</td>
					<td>
						<select>
							<option>분류선택</option>
							<option value=1>공지</option>
							<option value=2>질문</option>
							<option value=3>질문답변</option>
							<option value=4>유머</option>
							<option value=5>일상생활</option>
						</select>
					</td>
					<td width="50px;"></td>
				</tr>
				<tr>
					<td class="bw_td">제목</td>
					<td><input type="text" size="100" name="title" id="title"></td>
				</tr>
				<tr>
					<td class="bw_td">내용</td>
					<td bgcolor="red">
						<textarea name="content" id="textAreaContent" rows="10" cols="100" style="width:100%; height:412px; min-width:610px; display:none;"><%=sb.toString() %></textarea>
					</td>
				</tr>
			</table>
			<table width="75%" class="b_tb">
				<tr>
					<td align="right">
							<input type="submit" value="글수정" id="btnWrite" class="bw_btn">
						<input type="button" value="다시 작성" id="btnReset" class="bw_btn">
						<a href="javascript:onclick=history.back();">
							<input type="button" value="취소" id="btnCancel" class="bw_btn"></a>
						<a href="#">
							<input type="button" value="목록" id="btnList" class="bw_btn"> </a>
					</td>
					<td width="50px;"></td>
				</tr>
			</table>
			
		</div>
	</form>
	<script type="text/javascript">
		var oEditors = [];
		nhn.husky.EZCreator.createInIFrame({
		    oAppRef: oEditors,
		    elPlaceHolder: "textAreaContent",
		    sSkinURI: "<%=request.getContextPath()%>/se2/SmartEditor2Skin.html",
		    fCreator: "createSEditor2"
		});
		//‘저장’ 버튼을 누르는 등 저장을 위한 액션을 했을 때 submitContents가 호출된다고 가정한다.
		function submitContents(elClickedObj) {
		    // 에디터의 내용이 textarea에 적용된다.
		    oEditors.getById["textAreaContent"].exec("UPDATE_CONTENTS_FIELD", [ ]);
		    // 에디터의 내용에 대한 값 검증은 이곳에서
		    // document.getElementById("textAreaContent").value를 이용해서 처리한다.
		    try {
		        elClickedObj.form.submit();
		    } catch(e) {
		    }
		}
		// textArea에 이미지 첨부
		function pasteHTML(filepath){
		    var sHTML = '<img src="<%=request.getContextPath()%>/se2/upload/'+filepath+'">';
		    oEditors.getById["textAreaContent"].exec("PASTE_HTML", [sHTML]); 
		}
	</script>
</body>
</html>